<template>
  <div class="swiper-container swiper-no-swiping" ref="floorSwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(item, index) in list" :key="item.id">
        <img :src="item.imgUrl" />
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
export default {
  name: "Carousel",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    list: {
      handler() {
        this.$nextTick(() => {
          new Swiper(this.$refs.floorSwiper, {
            //在vue中使用swiper建议使用ref绑定元素,用id的话只能有一个swiper生效
            autoplay: {
              //自动切换
              delay: 2500, //时延
              disableOnInteraction: false,
            },
            loop: true,
            pagination: {
              el: ".swiper-pagination",
              clickable: true,
            },
      
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
          });
        });
      },
      immediate: true, //一开始监听不到list,因为这个数据从来都没发生过变化,是父组件给的,所以使用immediate立即监听一次
    },
  },
};
</script>

<style lang="less" scoped>
</style>